package com.didispace.impl;


import org.apache.axis.client.Call;  
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;  

public class Demoimpl {
	String result;
	public static void main(String[] args) {  
		  
        try {  
            String endpoint = "http://localhost:8080/ca3/services/caSynrochnized?wsdl";  
            // 直接引用远程的wsdl文件  
            // 以下都是套路  
            Service service = new Service();  
            Call call = (Call) service.createCall();  
            call.setTargetEndpointAddress(endpoint);  
            call.setOperationName("addUser");// WSDL里面描述的接口名称  
         //   call.addp  
            
            call.addParameter("userName",  
                    XMLType.XSD_DATE,  
                    javax.xml.rpc.ParameterMode.IN);// 接口的参数  
            call.setReturnType(XMLType.XSD_STRING);// 设置返回类型
            String temp = "测试人员";  
            String result = (String) call.invoke(new Object[] { temp });  
            // 给方法传递参数，并且调用方法  
            System.out.println("result is " + result);  
        } catch (Exception e) {  
            System.err.println(e.toString());  
        }  
    } 
	
	public  String AccessService(String Url,String MethodName,String[] ParameterName,Object[] Parameter) throws Exception{
		if(Url==""||Url==null) {
			return "Url的值为空";
		}
		if(MethodName==""||MethodName==null) {
			return "MethodName的值为空";
		}
		if(ParameterName.length==0) {
			return "ParameterName的值为空";
		}
		if(Parameter.length==0) {
			return "Parameter的值为空";
		}
		Service service = new Service();  
        Call call = (Call) service.createCall();  
        call.setTargetEndpointAddress(Url);
        call.setOperationName(MethodName);// WSDL里面描述的接口名称  
		for(int i=0;i<ParameterName.length;i++) {
			call.addParameter((String)ParameterName[i],
                    XMLType.XSD_DATE,  
                    javax.xml.rpc.ParameterMode.IN); //添加参数名称
		}
		 call.setReturnType(XMLType.XSD_STRING);// 设置返回类型
		 result = call.invoke(Parameter).toString();
		 return result;
	}
	
}
